package FilterChain知识;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@Component
@WebFilter(urlPatterns = "/demo/*")
public class LoggingFilterDemo implements Filter {
    @Override
    public void init(FilterConfig filterConfig) {
        System.out.println("LoggingFilter 初始化");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("LoggingFilter: 请求开始...");

        // 执行下一个过滤器或目标资源
        chain.doFilter(request, response);
        System.out.println("LoggingFilter: 响应返回...");
    }

    @Override
    public void destroy() {
        System.out.println("LoggingFilter 销毁");
    }
}
